package com.briup.cms.web.controller;

import com.briup.cms.bean.Category;
import com.briup.cms.service.ICategoryService;
 import com.briup.cms.utils.Message;
 import com.briup.cms.utils.MessageUtil;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;

 @Api(tags = {"资讯栏目相关接口"})
 @RestController
 @RequestMapping({"/auth/category"})
 public class CategoryController
       {
       @Autowired
     private ICategoryService categoryService;

     @ApiOperation(value = "分页查询所有资讯分类", notes = "包含所以一级栏目和二级栏目")
       @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query")})
      @GetMapping({"/page/queryAll"})
      public Message pageQueryAll(int pageNum, int pageSize) {
           PageInfo<Category> data = this.categoryService.pageQueryAll(pageNum, pageSize);
            return MessageUtil.success(data);
         }
      @ApiOperation(value = "查询所有栏目", notes = "不分页")
      @GetMapping({"/find/all"})
     public Message findAll() {
           List<Category> list = this.categoryService.findAll();
            return MessageUtil.success(list);
           }

       @ApiOperation("通过id删除栏目")
     @DeleteMapping({"/deleteById"})
     public Message deleteById(int id) {
            this.categoryService.deleteById(id);
           return MessageUtil.success("删除成功");
           }

     @ApiOperation("批量删除栏目")
      @DeleteMapping({"/batchDelete"})
       public Message batchDelete(int[] ids) {
          this.categoryService.batchDelete(ids);
            return MessageUtil.success("删除成功");
           }


      @ApiOperation("保存栏目信息")
       @PostMapping({"/save"})
     public Message saveCategory(Category category) {
           this.categoryService.saveCategory(category);
            return MessageUtil.success("保存栏目成功");
           }

       @ApiOperation("更新栏目信息")
       @PutMapping({"/update"})
      public Message updateCategory(Category category) {
            this.categoryService.updateCategory(category);
             return MessageUtil.success("更新栏目成功");
           }
 }
